package com.wenya.counter.ui.main;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.wenya.counter.R;

/**
 * @ProjectName: planning
 * @Package: com.xwl.yaru.planning.business.index.weight
 * @ClassName: MenuPop
 * @Description: java类作用描述
 * @Author: 谢文良
 * @CreateDate: 2020/6/11 14:36
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/6/11 14:36
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MenuPop implements View.OnClickListener {
    private PopupWindow popupWindow;
    private Listener listener;

    public MenuPop(Activity activity) {
        View view = activity.getLayoutInflater().inflate(R.layout.index_menu, null);
        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setOutsideTouchable(true);
        view.findViewById(R.id.add).setOnClickListener(this);
        view.findViewById(R.id.edita).setOnClickListener(this);
    }

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    public void showAsDropDown(View parent, float x, float y) {
        popupWindow.showAsDropDown(parent, (int) x, (int) y);
    }

    public void dismiss() {
        popupWindow.dismiss();
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        if (listener == null) {
            return;
        }
        switch (v.getId()) {
            case R.id.add:
                listener.add();
                break;
            case R.id.edita:
                listener.edita();
                break;
        }
        dismiss();
    }

    public interface Listener {
        void add();

        void edita();
    }
}
